<template>
	<view>
		<button type="default" @click="startRecord">开始录音</button>
		<button type="default" @click="stopRecord">停止录音</button>
		<button type="default" @click="palyVoice">播放录音</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				voicePath:''
			}
		},
		methods: {
			palyVoice(){
				this.innerAudioContext.src = this.voicePath
				this.innerAudioContext.play()
			},
			startRecord(){
				this.recorderManager.start();
			},
			stopRecord(){
				this.recorderManager.stop()
			}
		},
		onLoad() {
			this.innerAudioContext = uni.createInnerAudioContext(); // 声音的播放器
			this.recorderManager = uni.getRecorderManager(); // 录音管理器
			this.recorderManager.onStop((res)=>{ // 在停止录音时回调执行
				this.voicePath = res.tempFilePath
			})
			
		}
	}
</script>

<style>

</style>
